import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.io.PrintWriter;
//@WebFilter("/test.html")
public class FirstFilter implements Filter {//实现Filter接口
	FilterConfig config = null;//定义一个FilterConfig对象为类的实例变量
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		config = filterConfig;//获取FilterConfig对象引用
	}
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
							 FilterChain chain) throws IOException, ServletException {
		//response.setCharacterEncoding("utf-8");
		String str = config.getInitParameter("course");//获取过滤器初始参数
		response.setContentType("text/html;charset=gb2312");
		PrintWriter out = response.getWriter();
		System.out.println("测试");
		out.write("<font color=blue>前置程序块<br>");
		out.write("<font color=blue>前置程序块<br>");
		out.write("过滤器初始参数:course=" + str + "</font><br><br>");
		chain.doFilter(request,response);//调用"过滤器链"方法
		out.write("<br><font color=blue>后置程序块</font><br>");
	}
	@Override
	public void destroy() {//过滤器"销毁"方法
		config = null;
	}
}
